package com.mc.jf.apicontroller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mc.jf.entity.HttpListResponse;
import com.mc.jf.entity.Plan;
import com.mc.jf.entity.PlanUser;
import com.mc.jf.entity.ResUtil;
import com.mc.jf.service.impl.PlanServiceImpl;
import com.mc.jf.service.impl.PlanUserServiceImpl;
import com.mc.jf.utils.RoleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Lin
 * @since 2022-08-19
 */
@RestController
@RequestMapping("/api/planuser")
public class PlanUserApiController {

    @Autowired
    PlanUserServiceImpl planUserService;


    @GetMapping(value = "/all")
    public List<PlanUser> all() {

        if (RoleUtil.isAdmin()) {
            return planUserService.list();
        } else {
            LambdaQueryWrapper<PlanUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(PlanUser::getUsername, RoleUtil.getUser().getUsername());

            List<PlanUser> list = new ArrayList<>();
            list.add(planUserService.getOne(lambdaQueryWrapper));
            return list;
        }
    }

}
